#ifndef _ENCODING_CONVERT_
#define _ENCODING_CONVERT_

#include <iconv.h>
#include <stdio.h>
#include <string.h>
#include <iostream>


using namespace std;

class CodeConverter {
private:
    iconv_t cd;
public:
    CodeConverter(const char *from_charset,const char *to_charset) {
        cd = iconv_open(to_charset,from_charset);
    }

    ~CodeConverter() {
        iconv_close(cd);
    }

    size_t convert(char *inbuf,size_t inlen,char *outbuf,size_t outlen) {
        char **pin = &inbuf;
        char **pout = &outbuf;
        size_t len_convert;

        memset(outbuf,0,outlen);
        len_convert = iconv(cd,pin,&inlen,pout,&outlen);

        if((size_t)-1 == len_convert)
        printf("invalid string: %s \n",*pin);
        return len_convert;
    }
};

#endif
